package edu.udlap.spring2008.is300.finalexam.app.mvc.model.database.objects;

import edu.udlap.spring2008.is300.finalexam.framework.mvc.model.database.objects.CategoryRecord;
import edu.udlap.spring2008.is300.finalexam.framework.mvc.model.database.objects.FormatRecord;
import edu.udlap.spring2008.is300.finalexam.framework.mvc.model.database.objects.ImageRecord;
import edu.udlap.spring2008.is300.finalexam.framework.mvc.model.database.objects.PrivacyLevelRecord;
import edu.udlap.spring2008.is300.finalexam.framework.mvc.model.database.objects.SizeRecord;

/**
 *
 * @author Ruslán Ledesma Garza
 */
public class AppImageRecord implements ImageRecord {

    protected int id_;
    protected String path_;
    protected boolean isFavorite_;
    protected String description_;
    protected CategoryRecord categoryRecord_;
    protected SizeRecord sizeRecord_;
    protected FormatRecord formatRecord_;
    protected PrivacyLevelRecord privacyLevelRecord_;

    public AppImageRecord(int id,
            String path,
            boolean isFavorite,
            String description,
            CategoryRecord categoryRecord,
            SizeRecord sizeRecord,
            FormatRecord formatRecord,
            PrivacyLevelRecord privacyLevelRecord) {
        this.id_ = id;
        this.path_ = path;
        this.isFavorite_ = isFavorite;
        this.description_ = description;
        this.categoryRecord_ = categoryRecord;
        this.sizeRecord_ = sizeRecord;
        this.formatRecord_ = formatRecord;
        this.privacyLevelRecord_ = privacyLevelRecord;
    }

    @Override
    public int getId() {
        return id_;
    }

    @Override
    public String getPath() {
        return path_;
    }

    @Override
    public boolean isFavorite() {
        return isFavorite_;
    }

    @Override
    public String getDescription() {
        return description_;
    }

    @Override
    public CategoryRecord getCategory() {
        return categoryRecord_;
    }

    @Override
    public SizeRecord getSize() {
        return sizeRecord_;
    }

    @Override
    public PrivacyLevelRecord getPrivacyLevel() {
        return privacyLevelRecord_;
    }

    @Override
    public FormatRecord getFormat() {
        return formatRecord_;
    }

    @Override
    public boolean equals(Object obj)
    {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final AppImageRecord other = (AppImageRecord) obj;
        if (this.id_ != other.id_) {
            return false;
        }
        if (this.path_ != other.path_ && (this.path_ == null || !this.path_.equals(other.path_))) {
            return false;
        }
        if (this.isFavorite_ != other.isFavorite_) {
            return false;
        }
        if (this.description_ != other.description_ && (this.description_ == null || !this.description_.equals(other.description_))) {
            return false;
        }
        if (this.categoryRecord_ != other.categoryRecord_ && (this.categoryRecord_ == null || !this.categoryRecord_.equals(other.categoryRecord_))) {
            return false;
        }
        if (this.sizeRecord_ != other.sizeRecord_ && (this.sizeRecord_ == null || !this.sizeRecord_.equals(other.sizeRecord_))) {
            return false;
        }
        if (this.formatRecord_ != other.formatRecord_ && (this.formatRecord_ == null || !this.formatRecord_.equals(other.formatRecord_))) {
            return false;
        }
        if (this.privacyLevelRecord_ != other.privacyLevelRecord_ && (this.privacyLevelRecord_ == null || !this.privacyLevelRecord_.equals(other.privacyLevelRecord_))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode()
    {
        int hash = 7;
        hash = 67 * hash + this.id_;
        hash = 67 * hash + (this.path_ != null ? this.path_.hashCode() : 0);
        hash = 67 * hash + (this.isFavorite_ ? 1 : 0);
        hash = 67 * hash + (this.description_ != null ? this.description_.hashCode() : 0);
        hash = 67 * hash + (this.categoryRecord_ != null ? this.categoryRecord_.hashCode() : 0);
        hash = 67 * hash + (this.sizeRecord_ != null ? this.sizeRecord_.hashCode() : 0);
        hash = 67 * hash + (this.formatRecord_ != null ? this.formatRecord_.hashCode() : 0);
        hash = 67 * hash + (this.privacyLevelRecord_ != null ? this.privacyLevelRecord_.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString()
    {
        
        return  "<html>" +
                "   <table>" +
                "       <tr>" +
                "           <td>" +
                "               <img src=\"file:" + path_ + "\" width=\"30\" " +
                "               height=\"30\">" +
                "           </td><td>" +
                                description_ + " (" + path_ + ")" +
                "           </td>" +
                "       </tr>" +
                "   </table>" +
                "</html>";
        
        /*
        return "AppImageRecord #" + id_ + "\n" +
                "\tFavorite=" + isFavorite_ + "\n" +
                "\tDescription=" + description_ + "\n" +
                
                "\tcategoryId=" + categoryRecord_.getId() + "\n" +
                "\tcategoryDescription=" + categoryRecord_.getDescription() + "\n" +
                
                "\tsizeId=" + sizeRecord_.getId() + "\n" +
                "\tsizeDescription=" + sizeRecord_.getDescription() + "\n" +
                
                "\tformatId=" + formatRecord_.getId() + "\n" +
                "\tformatDescription=" + formatRecord_.getDescription() + "\n" +
                
                "\tprivacyLevelId=" + privacyLevelRecord_.getId() + "\n" +
                "\tprivacyLevelDescription=" + privacyLevelRecord_.getDescription() + "\n"
                
                ;*/
        
    }

    public void setFavorite(boolean value)
    {
        isFavorite_ = value;
    }

    public void setDescription(String value)
    {
        description_ = value;
    }

    public void setCategory(CategoryRecord value)
    {
        categoryRecord_ = value;
    }

    public void setSize(SizeRecord value)
    {
        sizeRecord_ = value;
    }

    public void setPrivacyLevel(PrivacyLevelRecord value)
    {
        privacyLevelRecord_ = value;
    }

    public void setFormat(FormatRecord value)
    {
        formatRecord_ = value;
    }
}
